<template>
  <div class="riskTrend-root">
    <formTitleVue
      title="风险趋势统计"
      :selectOptions="selectOptions"
    />
    <myBar domId="riskAnalysis-riskTrend-echarts" height="30vh" :chartsData="chartsData" :myOption="echartsOption"/>
  </div>
</template>

<script>
  import formTitleVue from "@/components/FormTitle/formTitle.vue";
  import myBar from '@/components/Echarts/myBar.vue';
  import { time_select_optios } from '@/utils/global.js';

  import { riskHazardCvHazardTaskTrend
  } from '@/api/risk/riskHazard'


  export default {
    name: "riskTrend",
    components: {
      formTitleVue,myBar,
    },
    props: {
      riskTypeOptions: {
        type: Array,
        default: [],
      },
      dateValueMap:{
        type: Object,
        default: {},
      },
      dataSelectOptions:{
        type: Array,
        default: [],
      }
    },
    data() {
      return {
        selectOptions: [
          {
            selectValue: "全部类型",
            options:this.riskTypeOptions,
            changeFn:this.changeType
          },
          {
            selectValue: 1,
            options:this.dataSelectOptions,
            changeFn:this.changeDate
          },
        ],
        chartsData: {
          xData: [],
          yData: [],
        },
        echartsOption:{

        },
        searChForm: {
          startTime: '',
          endTime: '',
          areaCode:'',
          placeType:'',
          dateType:'',
          sclassify:''
        },
      };
    },

    mounted() {
      this.changeDate(1)
    },
    methods: {
      changeType(val){
        console.log("changeType：",val)
        this.searChForm.sclassify = val
        this.getData()
      },
      changeDate(item){
        console.log("changeDate：",item)
        this.searChForm.startTime = this.dateValueMap[item].startTime
        this.searChForm.endTime = this.dateValueMap[item].endTime
        this.searChForm.dateType = "02"
        this.getData()
      },
      getData(){

        //this.chartsData.yData = [10, 20, 30, 40, 50, 60, 70];

        this.loading = true
        this.searChForm.areaCode = this.$store.state.account.user.deptIds;
        this.searChForm.placeType = this.$commonJs.getPlaceType(this.searChForm.areaCode);

        riskHazardCvHazardTaskTrend(this.searChForm).then((res) => {
          this.chartsData.xData = res.data.xAxle
          this.chartsData.yData = res.data.data.map(item=>{
            return {
              //name:item.name,
              data:item.report
            }
          })
          this.loading = false
          // this.draw(res.data);
        });
      },
    },
  };
</script>

<style lang="scss" scoped>
  .riskTrend-root {
  }
</style>
